package com.example.calcy;

import android.os.Bundle;
import android.app.Activity;
import android.text.Editable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {
     
	Button btnadd;
	Button btnsub;
	Button btnmul;
	Button btndiv;
	
	EditText etnum1;
	EditText etnum2;
		
	TextView tvresult;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        btnadd = (Button) findViewById(R.id.btnadd);
        btnsub = (Button) findViewById(R.id.btnsub);
        btnmul = (Button) findViewById(R.id.btnmul);
        btndiv = (Button) findViewById(R.id.btndiv);
        
        tvresult = (TextView) findViewById(R.id.tvresult);
        
        
        etnum1 = (EditText) findViewById(R.id.etnum1);
        etnum2 = (EditText) findViewById(R.id.etnum2);
        
        btnadd.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				add(etnum1.getText(),etnum2.getText());
				
			}
		});
        
        btnsub.setOnClickListener(new OnClickListener() {
			
     			@Override
     			public void onClick(View v) {
     				sub(etnum1.getText(),etnum2.getText());
     				
     			}
     		});
        btnmul.setOnClickListener(new OnClickListener() {
			
 			@Override
 			public void onClick(View v) {
 				mul(etnum1.getText(),etnum2.getText());
 				
 			}
 		});
        
        btndiv.setOnClickListener(new OnClickListener() {
			
 			@Override
 			public void onClick(View v) {
 				div(etnum1.getText(),etnum2.getText());
 				
 			}
 		});
        
        
    
    
   }
    protected void add(Editable etnum1,Editable etnum2)
    {
    	float num1 = Float.parseFloat(etnum1.toString());
    	float num2 = Float.parseFloat(etnum2.toString());
    	float result = num1 + num2;
    	tvresult.setText(String.valueOf(result));
    }
    
    protected void sub(Editable etnum1,Editable etnum2)
    {
    	float num1 = Float.parseFloat(etnum1.toString());
    	float num2 = Float.parseFloat(etnum2.toString());
    	float result = num1 - num2;
    	tvresult.setText(String.valueOf(result));
    }
    
    protected void mul(Editable etnum1,Editable etnum2)
    {
    	float num1 = Float.parseFloat(etnum1.toString());
    	float num2 = Float.parseFloat(etnum2.toString());
    	float result = num1 * num2;
    	tvresult.setText(String.valueOf(result));
    }
    
    protected void div(Editable etnum1,Editable etnum2)
    {
    	float num1 = Float.parseFloat(etnum1.toString());
    	float num2 = Float.parseFloat(etnum2.toString());
    	float result = num1 / num2;
    	tvresult.setText(String.valueOf(result));
    }
    }

